package day03;

public class Demo07 {
    public static void main(String[] args) {
        //移动零
        int[] nums = {0,1,5,0,3,0,4,6,9,0,4};
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
        System.out.println("移动后的数组为：");
        int a = 0;
        int b = 0;
        int t;
            while(b < nums.length){
               if(nums[b] != 0){//先把不等于零的值与前面的互换，然后零就被换到最后面了
                   t = nums[a];
                   nums[a] = nums[b];
                   nums[b] = t;
                   a++;
            }

               b++;
        }
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
    }
}
